package mware_lib.tcp;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.Socket;
import java.net.SocketAddress;

public class Connection {
  private ObjectInputStream in;
  private ObjectOutputStream out;
  protected Socket socket;
 

  public Connection(Socket mySock) throws IOException {
    socket = mySock;
    out = new ObjectOutputStream(mySock.getOutputStream());
    in = new ObjectInputStream(mySock.getInputStream());
  }
  
  public Object readObject() throws IOException {
    try {
      return in.readObject();
    } catch (ClassNotFoundException ex) {
      throw new RuntimeException("Klasse zu dem im Stream gesendeten Objekt konnte nicht gefunden werden!");
    }
  }
  
  public void writeObject(Serializable o) throws IOException {
    out.writeObject(o);
  }
  
  public byte readByte() throws IOException {
    return in.readByte();
  }
  
  public void writeByte(byte b) throws IOException {
    out.writeByte(b);
  }
  
  public void flush() throws IOException {
    out.flush();
  }

  public void close() throws IOException {
    in.close();
    out.close();
  }
  
  public SocketAddress getRemoteAddress()
  {
      return socket.getRemoteSocketAddress();
  }
}
